home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / game / shoot / ADoom_src_1_2.lha / ADoom_src / amiga_music.s < prev    next >
Text File  |  1998-02-28  |  42KB  |  1,925 lines

  1.         mc68020
  2. ;        multipass
  3. ;    if (_eval(DEBUG)&$8000)
  4. ;        debug    on,lattice4
  5. ;    endc
  6.  
  7. ; 2 channel .MUS player
  8. ;
  9. ; Derived by Peter McGavin,
  10. ; mostly by cutting and pasting large chunks of code from Amiga .MUS player
  11. ; originally by Joseph Fenton, Microcode Solutions, jlfenton@ctaz.com
  12. ; and his brother Michael.
  13.  
  14. ; void I_InitMusic (void);
  15.  
  16. ; void I_ShutdownMusic (void);
  17.  
  18. ; void I_SetMusicVolume (int volume);    // Volume.
  19.  
  20. ; void I_PauseSong (int handle);    // PAUSE game handling.
  21.  
  22. ; void I_ResumeSong (int handle);
  23.  
  24. ; int I_RegisterSong (void *data);    // Registers a song handle to song data.
  25.  
  26. ;// Called by anything that wishes to start music.
  27. ;//  plays a song, and when the song is done,
  28. ;//  starts playing it again in an endless loop.
  29. ;// Horrible thing to do, considering.
  30. ; void I_PlaySong (int handle, int looping);
  31.  
  32. ; void I_StopSong (int handle);        // Stops a song over 3 seconds.
  33.  
  34. ; void I_UnRegisterSong (int handle);    // See above (register), then think backwards
  35.  
  36. ;------------------------------------------------------------------------
  37.         xdef    @I_InitMusic      ; Allocate audio channels and clear them.
  38.         xdef    @I_ShutdownMusic  ; Clear channels and free them.
  39.         xdef    @I_SetMusicVolume ; Do code equiv to J_VolBox.
  40.         xdef    @I_PauseSong      ; Do code equiv to DoPause.
  41.         xdef    @I_ResumeSong      ; Goes to J_PlayBox equiv code.
  42.         xdef    @I_RegisterSong      ; Do code equiv to LoadMUS; no need to actually load it
  43.                       ; as we are passed a pointer to it here.
  44.         xdef    @I_PlaySong      ; Do code equiv to J_PlayBox.
  45.         xdef    @I_StopSong      ; Do code equiv to J_StopBox.
  46.         xdef    @I_UnRegisterSong ; Do code equiv to FreeUpMUS.
  47.  
  48. ;-----------------------------------------------------------------------
  49.         section    text,code
  50.  
  51.         near    a4,-2
  52.  
  53. ;------------------------------------------------------------------------
  54.         xref    _SysBase
  55.         xref    _DOSBase
  56.         xref    _GfxBase
  57.         xref    _custom
  58.         xref    _snd_MusicVolume
  59.         xref    _gametic
  60.         xref    _I_Error
  61.         xref    @M_CheckParm
  62.  
  63. ;------------------------------------------------------------------------
  64.  
  65.         include "exec/types.i"
  66.         include "exec/memory.i"
  67.         include "exec/funcdef.i"
  68.         include "exec/exec_lib.i"
  69.         include "dos/dos.i"
  70.         include "dos/dos_lib.i"
  71.         include "graphics/gfxbase.i"
  72.         include "devices/audio.i"
  73.         include    "hardware/custom.i"
  74.         include    "hardware/intbits.i"
  75.  
  76. TICRATE        equ    35            ; see doomdef.h
  77.  
  78. CALLSYS        macro    ;FunctionName
  79.         jsr    _LVO\1(a6)
  80.         endm
  81.  
  82. CALLEXE        macro    ;FunctionName
  83.         movea.l    (_SysBase),a6
  84.         jsr    _LVO\1(a6)
  85.         endm
  86.  
  87. CALLDOS        macro    ;FunctionName
  88.         movea.l    (_DOSBase),a6
  89.         jsr    _LVO\1(a6)
  90.         endm
  91.  
  92. ;_LVOCreatePool    equ    -696            ; not in Macro68's autoincludes
  93. ;_LVODeletePool    equ    -702            ; not in Macro68's autoincludes
  94.  
  95. ;------------------------------------------------------------------------
  96. ; void I_InitMusic (void);
  97. ; Allocate audio channels and clear them.
  98.  
  99. @I_InitMusic    movem.l    d0-d7/a0-a6,-(sp)
  100.  
  101.         movea.l    #musicarg,a0
  102.         jsr    @M_CheckParm
  103.         tst.l    d0
  104.         beq    .exit
  105.  
  106.         suba.l    a1,a1            ; this task
  107.         CALLEXE FindTask
  108.         move.l    d0,AudioTask        ; set task to signal
  109.  
  110.         move.w    #162,(per)
  111.         move.w    #325,(per2)        ; 11025 Hz, NTSC
  112.         move.l    (_GfxBase),a6
  113.         move.w    (gb_DisplayFlags,a6),d0
  114.         btst    #PALn,d0
  115.         beq.b    2$
  116.         move.w    #161,(per)
  117.         move.w    #322,(per2)        ; 11025 Hz, PAL
  118. 2$
  119.         moveq    #0,d0
  120.         moveq    #0,d1
  121.         lea    AudioName,a0
  122.         lea    AudioIO,a1
  123.         clr.l    ioa_Length(a1)        ; don't allocate channels yet
  124.         CALLEXE OpenDevice
  125.         tst.l    d0
  126.         beq    1$
  127.  
  128.         move.l    #cantopenaud,-(sp)
  129.         jsr    _I_Error
  130.         bra    .exit
  131.  
  132. 1$        move.b    #-1,AudioOK
  133.         bsr    AllocChannels        ; allocate channels
  134. .exit
  135.         movem.l    (sp)+,d0-d7/a0-a6
  136.         rts
  137.  
  138. ;------------------------------------------------------------------------
  139. ; void I_ShutdownMusic (void);
  140. ; Clear channels and free them.
  141.  
  142. @I_ShutdownMusic
  143.         movem.l    d0-d7/a0-a6,-(sp)
  144.         tst.b    AudioOK
  145.         beq    .exit
  146.         bsr    @I_StopSong
  147.         bsr    @I_UnRegisterSong    ; kill old mus
  148.         bsr    FreeChannels
  149.         lea    AudioIO,a1
  150.         CALLEXE CloseDevice
  151.         clr.b    AudioCh
  152.         clr.b    AudioOK
  153. .exit        movem.l    (sp)+,d0-d7/a0-a6
  154.         rts
  155.  
  156. ;------------------------------------------------------------------------
  157. ; void I_SetMusicVolume (int volume);    // Volume.
  158. ; Do code equiv to J_VolBox.
  159.  
  160. @I_SetMusicVolume
  161.         movem.l    d0-d7/a0-a6,-(sp)
  162.         tst.b    AudioOK
  163.         beq    .exit
  164.  
  165.         move.l    d0,(_snd_MusicVolume)
  166.         lsl.w    #3,d0            ; * 8
  167.         move.w    d0,AudioCh2Vol
  168.         move.w    d0,AudioCh3Vol
  169. .exit        movem.l    (sp)+,d0-d7/a0-a6
  170.         rts
  171.  
  172. ;------------------------------------------------------------------------
  173. ; void I_PauseSong (int handle);    // PAUSE game handling.
  174. ; Do code equiv to DoPause.
  175.  
  176. @I_PauseSong    movem.l    d0-d7/a0-a6,-(sp)
  177.         tst.b    AudioOK
  178.         beq    .done
  179.  
  180.         btst    #1,Flags        ; file loaded?
  181.         beq.b    .done
  182.         bset    #0,MusFlag        ; stop
  183.         bclr    #2,Flags        ; playing?
  184.         beq.b    .done
  185. .stop        btst    #0,MusFlag        ; music stopped?
  186.         bne.b    .stop
  187.  
  188.         cmpi.b    #12,AudioCh        ; locked?
  189.         bne.b    .done
  190.         lea    _custom,a0        ; kill sound
  191.         moveq    #0,d0
  192.         move.w    d0,aud2+ac_vol(a0)
  193.         move.w    d0,aud3+ac_vol(a0)
  194.  
  195. .done        movem.l    (sp)+,d0-d7/a0-a6
  196.         rts
  197.  
  198. ;------------------------------------------------------------------------
  199. ; void I_ResumeSong (int handle);
  200. ; Goes to J_PlayBox equiv code.
  201.  
  202. @I_ResumeSong    movem.l    d0-d7/a0-a6,-(sp)
  203.         tst.b    AudioOK
  204.         beq    .exit
  205.  
  206.         btst    #1,Flags        ; file loaded?
  207.         beq.b    .nofile
  208.  
  209.         cmpi.b    #12,AudioCh        ; got all channels?
  210.         beq.b    .allch
  211.         bsr    AllocChannels        ; try to alloc, first
  212.         cmpi.b    #12,AudioCh        ; now?
  213.         beq.b    .allch
  214.  
  215.         move.l    #cantgetchan,-(sp)
  216.         jsr    _I_Error
  217.         bra    .exit
  218.  
  219. .allch        bset    #2,Flags        ; playing?
  220.         beq.b    .ok
  221. .nofile        rts
  222.  
  223. .ok        movea.l    MusPtr,a0
  224.         moveq    #0,d1
  225.         move.b    8(a0),d1        ; d1 = # of channels
  226.  
  227.         moveq    #0,d0
  228.         move.w    6(a0),d0        ; score start
  229.         ror.w    #8,d0
  230.         adda.l    d0,a0            ; a0 = start
  231.         bclr    #3,Flags        ; paused?
  232.         bne    .paused
  233.  
  234.         move.l    a0,MusIndex        ; MusIndex = start
  235.  
  236.         move.l    #QuietInst,Channel0
  237.         move.l    #QuietInst,Channel1
  238.         move.l    #QuietInst,Channel2
  239.         move.l    #QuietInst,Channel3
  240.         move.l    #QuietInst,Channel4
  241.         move.l    #QuietInst,Channel5
  242.         move.l    #QuietInst,Channel6
  243.         move.l    #QuietInst,Channel7
  244.         move.l    #QuietInst,Channel8
  245.         move.l    #QuietInst,Channel9
  246.         move.l    #QuietInst,Channel10
  247.         move.l    #QuietInst,Channel11
  248.         move.l    #QuietInst,Channel12
  249.         move.l    #QuietInst,Channel13
  250.         move.l    #QuietInst,Channel14
  251.         move.l    #QuietInst,Channel15
  252.  
  253.         clr.l    MusDelay        ; MusDelay = 0
  254.         clr.b    MusFlag            ; enable music
  255.         clr.l    VoiceAvail        ; all voices available
  256.  
  257.         clr.l    MyTicks            ; reset my timer
  258.  
  259. .paused        CALLEXE Disable
  260.         lea    _custom,a0
  261.         move.w    #$8200,intena(a0)    ; int enable
  262.         move.w    #$800c,dmacon(a0)    ; enable dma
  263.         bsr    AudioINT2        ; start audio
  264.         CALLSYS    Enable
  265.  
  266. .exit        movem.l    (sp)+,d0-d7/a0-a6
  267.         rts
  268.  
  269. ;------------------------------------------------------------------------
  270. ; int I_RegisterSong (void *data);    // Registers a song handle to song data.
  271. ; Do code equiv to LoadMUS; no need to actually load it
  272. ; as we are passed a pointer to it here.
  273.  
  274. @I_RegisterSong
  275.         movem.l    d0-d7/a0-a6,-(sp)
  276.         tst.b    AudioOK
  277.         beq    .done2
  278.  
  279.         move.l    a0,-(sp)        ; save data ptr
  280.  
  281.         bsr    @I_StopSong        ; stop current mus
  282.         bsr    @I_UnRegisterSong    ; kill old mus
  283.  
  284.         movea.l    (sp)+,a0
  285.         move.l    a0,MUSMemPtr
  286.  
  287.         cmpi.l    #$4D55531A,(a0)        ; "MUS",26
  288.         bne    .uerror            ; not a mus file
  289.  
  290.         move.l    MUSMemPtr(pc),MusPtr
  291.  
  292.         bsr    TestMUSFile
  293.         beq    .berror
  294.  
  295. ;--------
  296.  
  297.         move.l    InstrFile,d1
  298.         move.l    #MODE_OLDFILE,d2
  299.         CALLDOS    Open
  300.         move.l    d0,InstrHandle
  301.         beq    .midierror
  302.  
  303.         move.l    #MEMF_CLEAR,d0        ; any memory
  304.         move.l    #65536,d1        ; puddle size
  305.         move.l    #32768,d2        ; threshold size
  306.         bsr    CreatePool
  307.         move.l    a0,InstrPool        ; this was d0
  308.         beq    .merror
  309.  
  310.         movea.l    a0,a2            ; so was this
  311.         movea.l    MusPtr,a3
  312.  
  313.         move.w    #255,d0
  314.         lea    Instruments,a0
  315. .setinstr    move.l    #QuietInst,(a0)+
  316.         dbra    d0,.setinstr
  317.  
  318.         move.w    $C(a3),d4        ; instrCnt
  319.         ror.w    #8,d4
  320.         subq.w    #1,d4            ; for dbra
  321.  
  322.         lea    $10(a3),a3        ; instruments[]
  323.  
  324. .instrloop    moveq    #14,d0
  325.         movea.l    a2,a0
  326.         bsr    AllocPooled
  327.  
  328.         moveq    #0,d2
  329.         move.b    (a3)+,d2        ; instrument #
  330.         moveq    #0,d1
  331.         move.b    (a3)+,d1        ; offset to next instr. #
  332.         adda.l    d1,a3            ; skip it (whatever it is?)
  333.  
  334.         lea    Instruments,a0
  335.         move.l    d0,(a0,d2.w*4)
  336.         beq    .merror
  337.  
  338.         movea.l    d0,a4            ; instrument record
  339.  
  340.         bftst    (validInstr){d2:1}
  341.         beq    .next            ; no instrument
  342.  
  343.         move.l    InstrHandle,d1
  344.         lsl.l    #2,d2
  345.         moveq    #OFFSET_BEGINNING,d3
  346.         CALLDOS    Seek
  347.  
  348.         move.l    InstrHandle,d1
  349.         move.l    a4,d2
  350.         moveq    #4,d3
  351.         CALLSYS    Read            ; get instrument offset
  352.         addq.l    #1,d0
  353.         beq    .ferror            ; can't read file
  354.  
  355.         move.l    InstrHandle,d1
  356.         move.l    (a4),d2
  357.         moveq    #OFFSET_BEGINNING,d3
  358.         CALLSYS    Seek
  359.  
  360.         move.l    InstrHandle,d1
  361.         move.l    a4,d2
  362.         moveq    #14,d3
  363.         CALLSYS    Read            ; get instrument header
  364.         addq.l    #1,d0
  365.         beq    .ferror            ; can't read file
  366.  
  367.         move.l    in_Length(a4),d0
  368.         swap    d0
  369.         movea.l    a2,a0
  370.         bsr    AllocPooled
  371.         move.l    d0,in_Wave(a4)        ; wave data buffer
  372.         beq    .merror
  373.  
  374.         move.l    InstrHandle,d1
  375.         move.l    d0,d2
  376.         move.l    in_Length(a4),d3
  377.         swap    d3
  378.         CALLDOS    Read            ; get instrument samples
  379.         addq.l    #1,d0
  380.         beq    .ferror            ; can't read file
  381.  
  382.         move.b    #1,in_Flags(a4)
  383. .next        dbra    d4,.instrloop
  384.  
  385.         bset    #1,Flags        ; file loaded
  386.         bsr    FillEventBlocks
  387.  
  388. .done        btst    #1,Flags        ; success?
  389.         bne.b    .exit
  390.         bsr    @I_UnRegisterSong    ; kill MUS and instruments
  391.  
  392. .exit        move.l    InstrHandle,d1
  393.         beq.b    .done2
  394.         CALLDOS    Close
  395.         clr.l    InstrHandle
  396.  
  397. .done2        moveq    #1,d0            ; return handle=1
  398.         movem.l    (sp)+,d0-d7/a0-a6
  399.         rts
  400.  
  401. ;---------
  402.  
  403. .midierror    move.l    #midifileproblem,-(sp)
  404.         jsr    _I_Error
  405.         bra    .done
  406.  
  407. .ferror        move.l    #dosproblem,-(sp)
  408.         jsr    _I_Error
  409.         bra    .done
  410.  
  411. .merror        move.l    #memproblem,-(sp)
  412.         jsr    _I_Error
  413.         bra    .done
  414.  
  415. .uerror        move.l    #notmusfile,-(sp)
  416.         jsr    _I_Error
  417.         bra    .done
  418.  
  419. .berror        move.l    #damagedfile,-(sp)
  420.         jsr    _I_Error
  421.         bra    .done
  422.  
  423. ;------------------------------------------------------------------------
  424. ;// Called by anything that wishes to start music.
  425. ;//  plays a song, and when the song is done,
  426. ;//  starts playing it again in an endless loop.
  427. ;// Horrible thing to do, considering.
  428. ; void I_PlaySong (int handle, int looping);
  429. ; Do code equiv to J_PlayBox.
  430.  
  431. @I_PlaySong    movem.l    d0-d7/a0-a6,-(sp)
  432.         tst.b    AudioOK
  433.         beq    .exit
  434.  
  435.         move.l    #TICRATE*30,d0
  436.         add.l    (_gametic),d0
  437.         move.l    d0,(musicdies)
  438.  
  439.         bsr    @I_ResumeSong
  440.  
  441. .exit        movem.l    (sp)+,d0-d7/a0-a6
  442.         rts
  443.  
  444. ;------------------------------------------------------------------------
  445. ; void I_StopSong (int handle);        // Stops a song over 3 seconds.
  446. ; Do code equiv to J_StopBox.
  447.  
  448. @I_StopSong    movem.l    d0-d7/a0-a6,-(sp)
  449.  
  450.         move.l    #0,(looping)
  451.         move.l    #0,(musicdies)
  452.  
  453.         tst.b    AudioOK
  454.         beq    .exit
  455.  
  456.         bsr    @I_PauseSong
  457.         bsr    KillAllAud
  458.  
  459. .exit        movem.l    (sp)+,d0-d7/a0-a6
  460.         rts
  461.  
  462. ;------------------------------------------------------------------------
  463. ; void I_UnRegisterSong (int handle);    // See above (register), then think backwards
  464. ; Do code equiv to FreeUpMUS.
  465.  
  466. @I_UnRegisterSong
  467.         movem.l    d0-d7/a0-a6,-(sp)
  468.  
  469.         tst.b    AudioOK
  470.         beq    .free
  471.  
  472.         bclr    #1,Flags        ; still have anything?
  473.         beq.b    .free
  474.  
  475.         clr.l    MUSMemPtr
  476.         clr.l    MUSMemSize
  477.  
  478. .instr        tst.l    InstrPool
  479.         beq.b    .free
  480.  
  481.         movea.l    InstrPool,a0
  482.         bsr    DeletePool
  483.         clr.l    InstrPool
  484.  
  485. .free        movem.l    (sp)+,d0-d7/a0-a6
  486.         rts
  487.  
  488. ;------------------------------------------------------------------------
  489. ;------------------------------------------------------------------------
  490.  
  491. FillEventBlocks    lea    EventBlocks,a4
  492.         movea.l    MusPtr(pc),a0
  493.         move.w    6(a0),d0
  494.         ror.w    #8,d0
  495.         lea    (a0,d0.w),a2        ; a2 = start
  496.         movea.l    a2,a1            ; a1 = a2
  497. .loop        bsr    NextDelay
  498.         move.l    a1,d0
  499.         sub.l    a2,d0            ; d0 = ptr - start
  500.         move.w    d0,(a4)+        ; store
  501.         addq.l    #1,d1
  502.         bne.b    .loop
  503.         clr.w    (a4)            ; end of offsets
  504.         rts
  505.  
  506. NextDelay    bsr.b    MyNextEvent
  507.         cmpi.b    #6,d1            ; score end
  508.         beq.b    .dd
  509.         tst.b    d0
  510.         bpl.b    NextDelay
  511.  
  512.         moveq    #0,d1            ; time = 0
  513. .d1        move.b    (a1)+,d0        ; get byte
  514.         bpl.b    .d2
  515.         andi.w    #$7F,d0            ; kill sign bit
  516.         or.b    d0,d1            ; time = time + 7 bits
  517.         lsl.l    #7,d1            ; * 128
  518.         bra.b    .d1            ; get next 7 bits
  519. .d2        or.b    d0,d1            ; time = time + last 7 bits
  520.         rts
  521.  
  522. .dd        moveq    #-1,d1
  523.         rts
  524.  
  525. MyNextEvent    move.b    (a1)+,d0        ; d0 = event
  526.         moveq    #$70,d1
  527.         and.b    d0,d1            ; d1 = type<<4
  528.         bne.b    .e1
  529.  
  530. .e0        addq.l    #1,a1            ; + value
  531.         rts
  532.  
  533. .e1        lsr.b    #4,d1            ; d1 = type
  534.         cmpi.b    #6,d1            ; score end?
  535.         bne.b    .e2
  536.         subq.l    #1,a1
  537. .ed        rts
  538. .e2        cmpi.b    #5,d1            ; no event
  539.         beq.b    .ed
  540.         cmpi.b    #7,d1            ; no event
  541.         beq.b    .ed
  542.         cmpi.b    #1,d1            ; play
  543.         beq.b    .ep
  544.         cmpi.b    #4,d1            ; change?
  545.         bne.b    .e0
  546.         addq.l    #2,a1            ; + value1, value2
  547.         rts
  548. .ep        moveq    #0,d4
  549.         tst.b    (a1)+            ; + note
  550.         bmi.b    .e0            ; (+ volume, if b7 set)
  551.         rts
  552.  
  553.         moveq    #1,d0
  554.         rts
  555.  
  556. ;------------------------------------------------------------------------
  557.  
  558. TestMUSFile    movea.l    MusPtr(pc),a0
  559.         move.l    MUSMemSize(pc),d3    ; d3 = total file size
  560.         moveq    #0,d0
  561.         move.w    4(a0),d0
  562.         beq    .fail
  563.         ror.w    #8,d0            ; score length
  564.         moveq    #0,d1
  565.         move.w    6(a0),d1
  566.         ror.w    #8,d1            ; score start
  567.         cmpi.w    #18,d1            ; start < 18? (1 instr.)
  568.         blt    .fail
  569.         add.l    d1,d0            ; d0 = total size
  570.  
  571. ;        cmp.l    d0,d3            ; = file size?
  572. ;        bne    .fail
  573.  
  574.         move.l    d0,d3
  575.         move.l    d3,MUSMemSize
  576.  
  577.         move.w    12(a0),d2
  578.         beq.b    .fail
  579.         ror.w    #8,d2            ; d2 = instr. count
  580.         subq.w    #1,d2
  581.         lea    16(a0),a1        ; a1 = * instr. list
  582. .loop        addq.l    #1,a1            ; skip instr. value
  583.         moveq    #0,d0
  584.         move.b    (a1)+,d0        ; d0 = offset to next instr.
  585.         adda.l    d0,a1            ; skip info (?)
  586.         dbra    d2,.loop        ; next
  587.         move.l    a1,d0            ; d0 = * data following list
  588.         sub.l    a0,d0            ; - file start
  589.         cmp.l    d0,d1            ; = start?
  590.         bne.b    .fail
  591.         move.b    -1(a0,d3.l),d0        ; get last byte
  592.         lsr.b    #4,d0
  593.         cmpi.b    #6,d0            ; last byte = $6x? (end)
  594.         bne.b    .fail
  595.         moveq    #1,d0            ; file okay
  596.         rts
  597. .fail        moveq    #0,d0            ; yikes!
  598.         rts
  599.  
  600. ;------------------------------------------------------------------------
  601. ;------------------------------------------------------------------------
  602.  
  603. ; stop, clear, turn off
  604.  
  605. KillAllAud    cmpi.b    #12,AudioCh        ; locked?
  606.         bne.b    .vk
  607.  
  608.         lea    _custom,a0
  609.         move.l    #ClearBuf,aud2(a0)    ; re-init
  610.         move.w    #80,aud2+ac_len(a0)
  611.         move.w    (per,pc),aud2+ac_per(a0)
  612.         move.l    #ClearBuf,aud3(a0)
  613.         move.w    #80,aud3+ac_len(a0)
  614.         move.w    (per,pc),aud3+ac_per(a0)
  615.  
  616. .vk        clr.b    Voice0+vc_Flags        ; disable voices
  617.         clr.b    Voice1+vc_Flags
  618.         clr.b    Voice2+vc_Flags
  619.         clr.b    Voice3+vc_Flags
  620.         clr.b    Voice4+vc_Flags
  621.         clr.b    Voice5+vc_Flags
  622.         clr.b    Voice6+vc_Flags
  623.         clr.b    Voice7+vc_Flags
  624.         clr.b    Voice8+vc_Flags
  625.         clr.b    Voice9+vc_Flags
  626.         clr.b    Voice10+vc_Flags
  627.         clr.b    Voice11+vc_Flags
  628.         clr.b    Voice12+vc_Flags
  629.         clr.b    Voice13+vc_Flags
  630.         clr.b    Voice14+vc_Flags
  631.         clr.b    Voice15+vc_Flags
  632.  
  633.         rts
  634.  
  635. ;------------------------------------------------------------------------
  636. ;------------------------------------------------------------------------
  637.  
  638. AllocChannels    lea    AudioIO,a1
  639.         move.w    #ADCMD_ALLOCATE,IO_COMMAND(a1)
  640.         move.b    #ADIOF_NOWAIT+IOF_QUICK,IO_FLAGS(a1)
  641.         move.l    #AudioAlloc,ioa_Data(a1)
  642.         move.l    #1,ioa_Length(a1)
  643.         movea.l    IO_DEVICE(a1),a6
  644.         jsr    DEV_BEGINIO(a6)
  645.         tst.l    d0
  646.         beq    1$
  647.  
  648.         move.l    #cantgetchan,-(sp)
  649.         jsr    _I_Error
  650.         bra    .exit
  651.  
  652. 1$        lea    AudioIO,a1
  653.         move.w    #ADCMD_LOCK,IO_COMMAND(a1)
  654.         CALLEXE SendIO
  655.  
  656.         move.l    AudioIO+IO_UNIT,d0
  657.         move.b    d0,AudioCh
  658.         cmpi.b    #12,d0            ; all channels?
  659.         beq    2$
  660.  
  661.         move.l    #cantgetchan,-(sp)
  662.         jsr    _I_Error
  663.         bra    .exit
  664.  
  665. 2$        lea    _custom,a0
  666.         move.w    #$0600,intena(a0)    ; kill int enable
  667.         move.w    #$0600,intreq(a0)    ; kill request
  668.         move.w    #$00FF,adkcon(a0)    ; kill modulation
  669.         move.w    #$000C,dmacon(a0)    ; disable dma
  670.  
  671.         move.l    #ClearBuf,aud2(a0)
  672.         move.w    #80,aud2+ac_len(a0)
  673.         move.w    (per,pc),aud2+ac_per(a0)
  674.         move.w    #0,aud2+ac_vol(a0)
  675.  
  676.         move.l    #ClearBuf,aud3(a0)
  677.         move.w    #80,aud3+ac_len(a0)
  678.         move.w    (per,pc),aud3+ac_per(a0)
  679.         move.w    #0,aud3+ac_vol(a0)
  680.  
  681.         moveq    #INTB_AUD2,d0
  682.         lea    AInt2,a1
  683.         CALLEXE SetIntVector
  684.         move.l    d0,OldAInt2
  685.  
  686. .exit        rts
  687.  
  688. ;------------------------------------------------------------------------
  689.  
  690. FreeChannels    cmpi.b    #12,AudioCh
  691.         bne.b    .exit            ; no channels
  692.  
  693.         lea    _custom,a0
  694.         move.w    #$0600,intena(a0)    ; kill int enable
  695.         move.w    #$0600,intreq(a0)    ; kill request
  696.  
  697.         moveq    #INTB_AUD2,d0
  698.         movea.l    OldAInt2,a1
  699.         CALLEXE SetIntVector
  700.  
  701.         moveq    #$000c,d0
  702.         move.w    d0,_custom+dmacon    ; dma off
  703.         lea    AudioIO,a1
  704.         move.w    #ADCMD_FREE,IO_COMMAND(a1)
  705.         move.b    #IOF_QUICK,IO_FLAGS(a1)
  706.         movea.l    IO_DEVICE(a1),a6
  707.         jsr    DEV_BEGINIO(a6)
  708.         clr.l    AudioIO+IO_UNIT
  709.         clr.b    AudioCh
  710.  
  711. .exit        rts
  712.  
  713. ;--------------------------------------------------------------------
  714.  
  715.         cnop    0,16
  716.  
  717. AudioINT2    movem.l    d2-d6/a2-a4/a6,-(a7)
  718.  
  719.         btst    #0,MusFlag
  720.         beq.b    .cont
  721.  
  722.         lea    _custom,a0
  723.         move.w    #$0600,intena(a0)    ; kill int enable
  724.         move.w    #$0600,intreq(a0)    ; kill request
  725.  
  726.         clr.b    MusFlag
  727.         bra    .exit
  728.  
  729. .cont        subq.l    #1,MusDelay
  730.         bpl.b    .setaudio
  731.  
  732.         bsr    NextEvent
  733.  
  734. .setaudio    bchg    #1,MusFlag        ; switch buffers
  735.  
  736.         btst    #6,Flags        ; gadget down?
  737.         bne.b    .gad
  738.         addq.l    #1,MyTicks        ; increment my timer
  739.  
  740. .gad        lea    Voice0,a0        ; music voices
  741.         lea    AudioCh2Buf,a2
  742.         bsr    FillBuffer
  743.  
  744.         lea    _custom,a0
  745.         move.w    #INTF_AUD2,intreq(a0)
  746.  
  747.         move.l    AudioCh2Ptr,aud2(a0)
  748.         move.w    #40,aud2+ac_len(a0)        ; 80 samples
  749.         move.w    (per2,pc),aud2+ac_per(a0)    ; 11048Hz
  750.         move.w    AudioCh2Vol,aud2+ac_vol(a0)
  751.  
  752.         move.l    AudioCh2Ptr,aud3(a0)
  753.         move.w    #40,aud3+ac_len(a0)        ; 80 samples
  754.         move.w    (per2,pc),aud3+ac_per(a0)    ; 11048Hz
  755.         move.w    AudioCh2Vol,aud3+ac_vol(a0)
  756.  
  757. .exit        movem.l    (a7)+,d2-d6/a2-a4/a6
  758.         moveq    #0,d0
  759.         rts
  760.  
  761. ;------------------------------------------------------------------------
  762.  
  763.         CNOP    0,16
  764.  
  765. FillBuffer    moveq    #0,d0
  766.         btst    #1,MusFlag
  767.         beq.b    .swap
  768.         move.l    #80,d0
  769. .swap        movea.l    (a2),a4            ; chip buffer
  770.         adda.l    d0,a4
  771.         move.l    a4,4(a2)        ; AudioChxPtr
  772.  
  773.         lea    tempAudio,a1
  774.         moveq    #4,d0
  775. .cloop        clr.l    (a1)+
  776.         clr.l    (a1)+
  777.         clr.l    (a1)+
  778.         clr.l    (a1)+
  779.         dbra    d0,.cloop
  780.  
  781. .next        move.l    vc_Next(a0),d0        ; next voice
  782.         bne.b    .chkvoice
  783.  
  784.         lea    tempAudio,a1
  785.         moveq    #4,d0
  786. .mloop        move.l    (a1)+,(a4)+
  787.         move.l    (a1)+,(a4)+
  788.         move.l    (a1)+,(a4)+
  789.         move.l    (a1)+,(a4)+
  790.         dbra    d0,.mloop
  791.         rts
  792.  
  793. .chkvoice    movea.l    d0,a0
  794.         btst    #0,vc_Flags(a0)
  795.         beq.b    .next            ; not enabled
  796.  
  797.  
  798. ;------------------
  799. ; do voice
  800.  
  801.         lea    tempAudio,a1
  802.  
  803.         btst    #1,vc_Flags(a0)
  804.         beq.b    .1            ; not releasing
  805.  
  806.         subq.b    #1,vc_Vol(a0)
  807.         bpl.b    .1
  808.         clr.b    vc_Vol(a0)
  809.         clr.b    vc_Flags(a0)        ; voice off
  810.         bra.b    .next
  811.  
  812. .1        move.b    vc_Vol(a0),d5
  813.         bfffo    d5{24:8},d5        ; 0-127 -> 32-24
  814.         subi.b    #24,d5            ;          8-0
  815.         addq.b    #2,d5            ; /4
  816.  
  817.         movem.l    vc_Index(a0),d1-d4    ; index,step,loop,length
  818.  
  819.         movea.l    vc_Channel(a0),a3
  820.         move.l    ch_Pitch(a3),d0
  821.         muls.l    d0,d6:d2
  822.         move.w    d6,d2
  823.         swap    d2
  824.         add.l    vc_Step(a0),d2        ; final sample rate
  825.  
  826.         movea.l    vc_Wave(a0),a3        ; sample data
  827.  
  828.         moveq    #79,d6            ; 80 samples
  829.  
  830. .floop        moveq    #0,d0
  831.         swap    d1
  832.         move.b    (a3,d1.w),d0        ; sample
  833.         swap    d1
  834.         asr.b    d5,d0
  835.         add.b    d0,(a1)+
  836.  
  837.         add.l    d2,d1
  838.         cmp.l    d4,d1
  839.         blo.b    .2
  840.         sub.l    d4,d1
  841.         add.l    d3,d1
  842.         tst.l    d3
  843.         beq.b    .3            ; no looping
  844. .2        dbra    d6,.floop
  845.         bra.b    .done            ; done with voice 1
  846.  
  847. ; ran out of data
  848. .3        clr.b    vc_Flags(a0)        ; voice off
  849.  
  850. .done        move.l    d1,vc_Index(a0)
  851.         bra    .next
  852.  
  853. ;------------------------------------------------------------------------
  854.  
  855.         CNOP    0,16
  856.  
  857. NextEvent    movea.l    MusIndex,a1
  858.  
  859. .0        move.b    (a1)+,d0        ; get next event
  860.         move.b    d0,d1
  861.         lsr.b    #3,d1
  862.         andi.w    #$E,d1            ; d1 = event type * 2
  863.         lea    EventTable,a0
  864.         move.w    (a0,d1.w),d1
  865.         jsr    (a0,d1.w)        ; do event
  866.         tst.b    d0
  867.         bpl.b    .0            ; more events
  868.  
  869.         moveq    #0,d1            ; time = 0
  870. .1        move.b    (a1)+,d0        ; get byte
  871.         bpl.b    .2
  872.  
  873.         andi.w    #$7F,d0            ; kill sign bit
  874.         or.b    d0,d1            ; time = time + 7 bits
  875.         lsl.l    #7,d1            ; * 128
  876.         bra.b    .1            ; get next 7 bits
  877.  
  878. .2        or.b    d0,d1            ; time = time + last 7 bits
  879.         subq.l    #1,d1            ; delay = time - 1
  880.         bmi.b    .0            ; (no delay)
  881.  
  882.         btst    #6,Flags        ; gadget down?
  883.         beq.b    .nogad
  884.         btst    #7,Flags
  885.         beq.b    .rev
  886.         add.l    d1,MyTicks        ; add to my timer
  887.         addq.l    #1,MyTicks        ; + 1
  888.         lsr.l    #3,d1            ; delay = delay / 8
  889.         bra.b    .nogad
  890. .rev        bsr.b    PrevBlock
  891.  
  892. .nogad        move.l    d1,MusDelay        ; store delay
  893.         move.l    a1,MusIndex        ; store index
  894.         rts
  895.  
  896. PrevBlock    move.l    PrevDelay,d0
  897.         sub.l    d0,MyTicks        ; sub previous value
  898.         addq.l    #1,d1
  899.         move.l    d1,PrevDelay
  900.         move.l    a1,d1            ; d1 = current ptr
  901.         movea.l    MusPtr(pc),a0
  902.         move.w    6(a0),d0
  903.         ror.w    #8,d0
  904.         lea    (a0,d0.w),a0        ; a0 = start
  905.         cmp.l    a0,d1            ; at start?
  906.         beq.b    .done
  907.         lea    EventBlocks,a1
  908. .loop        moveq    #0,d0
  909.         move.w    (a1)+,d0        ; offset
  910.         beq.b    .done            ; (not found)
  911.         add.l    a0,d0            ; ptr
  912.         cmp.l    d1,d0            ; = current?
  913.         bne.b    .loop
  914.         subq.l    #4,a1
  915.         cmpa.l    #EventBlocks,a1        ; 2nd block?
  916.         bls.b    .done
  917.         moveq    #0,d0
  918.         move.w    -(a1),d0        ; offset prev block
  919.         add.l    a0,d0
  920.         movea.l    d0,a1            ; ptr = prev block
  921.         moveq    #0,d1            ; delay = 0
  922.         rts
  923. .done        movea.l    a0,a1            ; ptr = start
  924.         moveq    #0,d1            ; delay = 0
  925.         clr.l    MyTicks            ; reset timer
  926.         rts
  927.  
  928. ;------------------------------------------------------------------------
  929.  
  930. Release        moveq    #15,d1
  931.         and.b    d0,d1            ; d1 = channel
  932.  
  933.         lea    Channels,a0
  934.         movea.l    (a0,d1.w*4),a0        ; channel record
  935.         movea.l    ch_Map(a0),a0        ; channel map
  936.  
  937.         move.b    (a1)+,d1        ; note #
  938.         moveq    #0,d2
  939.         move.b    (a0,d1.w),d2        ; voice #
  940.         beq.b    .exit            ; no mapping
  941.  
  942.         clr.b    (a0,d1.w)        ; clear mapping
  943.         move.l    VoiceAvail,d3
  944.         bclr    d2,d3            ; voice free for use
  945.         move.l    d3,VoiceAvail
  946.  
  947.         lea    Voices,a0
  948.         movea.l    (a0,d2.w*4),a0        ; voice
  949.         bset    #1,vc_Flags(a0)        ; do release
  950.  
  951. .exit        rts
  952.  
  953. ;------------------------------------------------------------------------
  954.  
  955. PlayNote    moveq    #15,d1
  956.         and.b    d0,d1            ; d1 = channel
  957.  
  958.         lea    Channels,a0
  959.         movea.l    (a0,d1.w*4),a2        ; channel record
  960.         movea.l    ch_Map(a2),a0        ; channel map
  961.  
  962.         moveq    #-1,d2            ; no volume change
  963.         move.b    (a1)+,d1        ; note #
  964.         bclr    #7,d1
  965.         beq.b    .getvc            ; no volume
  966.  
  967.         moveq    #0,d2
  968.         move.b    (a1)+,d2        ; volume
  969.  
  970. .getvc        moveq    #0,d3
  971.         move.l    VoiceAvail,d4
  972. .vloop        bset    d3,d4
  973.         beq.b    .foundfree
  974.         addq.b    #1,d3
  975.         cmpi.b    #16,d3
  976.         bne.b    .vloop
  977. ; no free voices
  978.         rts
  979.  
  980.  
  981. .foundfree    move.b    d3,(a0,d1.w)        ; voice mapping
  982.         move.l    d4,VoiceAvail
  983.  
  984.         lea    Voices,a0
  985.         movea.l    (a0,d3.w*4),a3        ; voice
  986.         btst    #7,vc_Flags(a3)
  987.         bne.b    .exit            ; sfx using channel
  988.  
  989.         tst.b    d2
  990.         bmi.b    .skip
  991.         move.b    d2,ch_Vol(a2)        ; new channel volume
  992. .skip        move.b    ch_Vol(a2),vc_Vol(a3)
  993.  
  994.         moveq    #15,d2
  995.         and.b    d0,d2
  996.         cmpi.b    #15,d2
  997.         beq.b    .percussion
  998.  
  999.         move.l    ch_Instr(a2),a4        ; instrument record
  1000.  
  1001.         lea    NoteTable,a0
  1002.         moveq    #72,d2            ; middle c
  1003.         sub.b    in_Base(a4),d2
  1004.         add.b    d1,d2
  1005.         move.l    (a0,d2.w*4),vc_Step(a3)    ; step value for note
  1006.  
  1007.         clr.l    vc_Index(a3)
  1008.  
  1009.         move.l    a2,vc_Channel(a3)    ; back link (for pitch wheel)
  1010.  
  1011.         move.l    in_Wave(a4),vc_Wave(a3)
  1012.         move.l    in_Loop(a4),vc_Loop(a3)
  1013.         move.l    in_Length(a4),vc_Length(a3)
  1014.         move.b    in_Flags(a4),vc_Flags(a3)
  1015. .exit        rts
  1016.  
  1017. ; for the percussion channel, the note played sets the percussion instrument
  1018.  
  1019. .percussion    move.l    #65536,vc_Step(a3)    ; sample rate always 1.0
  1020.  
  1021.         clr.l    vc_Index(a3)
  1022.  
  1023.         move.l    a2,vc_Channel(a3)    ; back link
  1024.  
  1025.         addi.b    #100,d1            ; percussion instruments
  1026.  
  1027.         lea    Instruments,a0
  1028.         move.l    (a0,d1.w*4),a0        ; instrument record
  1029.         move.l    in_Wave(a0),vc_Wave(a3)
  1030.         move.l    in_Loop(a0),vc_Loop(a3)
  1031.         move.l    in_Length(a0),vc_Length(a3)
  1032.         move.b    in_Flags(a0),vc_Flags(a3)
  1033.         rts
  1034.  
  1035. ;------------------------------------------------------------------------
  1036.  
  1037. Pitch        moveq    #15,d1
  1038.         and.b    d0,d1            ; d1 = channel
  1039.  
  1040.         lea    Channels,a0
  1041.         movea.l    (a0,d1.w*4),a2        ; channel record
  1042.  
  1043.         moveq    #0,d1
  1044.         move.b    (a1)+,d1        ; pitch wheel setting
  1045.         lea    PitchTable,a0
  1046.         move.l    (a0,d1.w*4),ch_Pitch(a2)
  1047.         rts
  1048.  
  1049. ;------------------------------------------------------------------------
  1050.  
  1051. Tempo        addq.l    #1,a1            ; skip value
  1052.         rts
  1053.  
  1054. ;------------------------------------------------------------------------
  1055.  
  1056. ChangeCtrl    moveq    #15,d1
  1057.         and.b    d0,d1            ; d1 = channel
  1058.  
  1059.         lea    Channels,a0
  1060.         movea.l    (a0,d1.w*4),a2        ; channel
  1061.  
  1062.         move.b    (a1)+,d1        ; get controller
  1063.  
  1064.         moveq    #0,d2
  1065.         move.b    (a1)+,d2        ; value
  1066.  
  1067.         tst.b    d1
  1068.         bne.b    .1
  1069.  
  1070. ; set channel instrument
  1071.  
  1072.         lea    Instruments,a0
  1073.         move.l    (a0,d2.w*4),ch_Instr(a2)
  1074.         bne.b    .0
  1075.         move.l    #QuietInst,ch_Instr(a2)
  1076. .0        rts
  1077.  
  1078. .1        cmpi.b    #3,d1            ; volume?
  1079.         bne.b    .2
  1080.  
  1081. ; set channel volume
  1082.  
  1083.         move.b    d2,ch_Vol(a2)
  1084.         rts
  1085.  
  1086. .2        cmpi.b    #4,d1            ; pan?
  1087.         bne.b    .exit
  1088.  
  1089. ; set channel pan
  1090.  
  1091.         move.b    d2,ch_Pan(a2)
  1092. .exit        rts
  1093.  
  1094. ;------------------------------------------------------------------------
  1095.  
  1096. NoEvent        rts
  1097.  
  1098. ;------------------------------------------------------------------------
  1099.  
  1100. EndScore    btst    #4,Flags        ; loop?
  1101.         beq.b    .loop
  1102.  
  1103.         lea    _custom,a0
  1104.         move.w    #$0600,intena(a0)    ; kill int enable
  1105.         move.w    #$0600,intreq(a0)    ; kill request
  1106.         clr.b    MusFlag            ; clear mus flag
  1107.         bclr    #2,Flags        ; kill playing flag
  1108.         moveq    #0,d0
  1109.         move.w    d0,aud2+ac_vol(a0)    ; kill old audio
  1110.         move.w    d0,aud3+ac_vol(a0)
  1111.         bsr    KillAllAud
  1112.         addq.l    #8,a7            ; pop NextEvent, AudioInt
  1113.         movem.l    (a7)+,d2-d6/a2-a4/a6    ; return from interrupt
  1114.         moveq    #0,d0
  1115.         rts
  1116.  
  1117. .loop        movea.l    MusPtr,a1
  1118.         moveq    #0,d1
  1119.         move.w    6(a1),d1        ; score start
  1120.         ror.w    #8,d1
  1121.         adda.l    d1,a1            ; a1 = start
  1122.  
  1123.         clr.l    MyTicks            ; reset my timer
  1124.         rts
  1125.  
  1126. ;------------------------------------------------------------------------
  1127. ;--------------------------------------------------------------------
  1128.  
  1129.         cnop    0,4
  1130.  
  1131. CreatePool    movea.l    _SysBase,a1
  1132.         cmpi.w    #39,LIB_VERSION(a1)
  1133.         blt.b    .nopools        ; change to bra for debugging
  1134.  
  1135.         move.l    a6,-(sp)
  1136.         movea.l    a1,a6
  1137.         CALLSYS    CreatePool
  1138.         movea.l    (sp)+,a6
  1139.         rts
  1140.  
  1141. .nopools    movem.l    d2-d7/a2-a6,-(sp)
  1142.         move.l    d0,d4            ; memory attributes
  1143.         move.l    d1,d3            ; amount to allocate when low
  1144.         move.l    d2,d5            ; size of when not to use pool
  1145.  
  1146.         exg.l    d0,d1            ; swap flags and size
  1147.         movea.l    a1,a6
  1148.         CALLSYS    AllocMem        ; get first block
  1149.         movea.l    d0,a0
  1150.         tst.l    d0
  1151.         beq.b    .exit            ; no memory!
  1152.  
  1153.         movem.l    d3-d5,(a0)        ; puddleSize, Flags,Threshold
  1154.         clr.l    12(a0)            ; no next block
  1155.         lea    24(a0),a1        ; first free location here
  1156.         move.l    a1,16(a0)
  1157.         subi.l    #24,d3            ; for header info
  1158.         move.l    d3,20(a0)        ; amount free in this block
  1159.  
  1160. .exit        movem.l    (sp)+,d2-d7/a2-a6
  1161.         rts
  1162.  
  1163.         cnop    0,4
  1164.  
  1165. DeletePool    movea.l    _SysBase,a1
  1166.         cmpi.w    #39,LIB_VERSION(a1)
  1167.         blt.b    .nopools        ; change to bra for debugging
  1168.  
  1169.         move.l    a6,-(sp)
  1170.         movea.l    a1,a6
  1171.         CALLSYS    DeletePool
  1172.         movea.l    (sp)+,a6
  1173.         rts
  1174.  
  1175. .nopools    movem.l    d2-d7/a2-a6,-(sp)
  1176.         move.l    a0,d2            ; first block
  1177.         beq.b    .exit            ; safety check
  1178.  
  1179.         movea.l    a1,a6
  1180.  
  1181. .loop        movea.l    d2,a1            ; pointer to block
  1182.         move.l    (a1),d0            ; size of block
  1183.         move.l    12(a1),d2        ; next block
  1184.         CALLSYS    FreeMem
  1185.         tst.l    d2
  1186.         bne.b    .loop
  1187.  
  1188. .exit        movem.l    (sp)+,d2-d7/a2-a6
  1189.         rts
  1190.  
  1191.         cnop    0,4
  1192.  
  1193. AllocPooled    movea.l    _SysBase,a1
  1194.         cmpi.w    #39,LIB_VERSION(a1)
  1195.         blt.b    .nopools        ; change to bra for debugging
  1196.  
  1197.         move.l    a6,-(sp)
  1198.         movea.l    a1,a6
  1199.         CALLSYS    AllocPooled
  1200.         movea.l    (sp)+,a6
  1201.         rts
  1202.  
  1203. .nopools    movem.l    d2-d7/a2-a6,-(sp)
  1204.         move.l    a0,d2
  1205.         beq.b    .exit            ; safety check
  1206.  
  1207.         addq.l    #3,d0
  1208.         andi.b    #$FC,d0            ; long align size
  1209.  
  1210.         movea.l    a1,a6
  1211.  
  1212.         cmp.l    8(a0),d0        ; check threshold
  1213.         blt.b    .chkpuddles        ; allocate from puddles
  1214.  
  1215.         addi.l    #24,d0            ; for header
  1216.         move.l    d0,d3            ; save size
  1217.         move.l    4(a0),d1        ; mem attrs
  1218.         CALLSYS    AllocMem
  1219.         movea.l    d0,a0
  1220.         tst.l    d0
  1221.         beq.b    .exit            ; no memory
  1222.  
  1223.         move.l    d3,(a0)            ; size of block
  1224.         clr.l    20(a0)            ; no free space in here
  1225.  
  1226.         movea.l    d2,a1            ; pool header
  1227.         move.l    12(a1),d1
  1228.         move.l    a0,12(a1)        ; splice in block
  1229.         move.l    d1,12(a0)        ; relink next block
  1230.         lea    24(a0),a0        ; skip over header
  1231.  
  1232. .exit        move.l    a0,d0
  1233.         movem.l    (sp)+,d2-d7/a2-a6
  1234.         rts
  1235.  
  1236.         cnop    0,4
  1237.  
  1238. .chkpuddles    cmp.l    20(a0),d0        ; check free space
  1239.         blt.b    .gotspace
  1240.  
  1241.         movea.l    12(a0),a0        ; next block
  1242.         move.l    a0,d1
  1243.         bne.b    .chkpuddles
  1244.  
  1245. ; not enough free space in existing puddles, create another
  1246.  
  1247.         move.l    d0,d6            ; save size
  1248.  
  1249.         movea.l    d2,a0            ; pool header
  1250.         movem.l    (a0),d3-d5
  1251.         movem.l    (a0),d0-d1
  1252.         CALLSYS    AllocMem        ; get block
  1253.         movea.l    d0,a0
  1254.         tst.l    d0
  1255.         beq.b    .out            ; no memory!
  1256.  
  1257.         movea.l    d2,a1            ; pool header
  1258.         movem.l    d3-d5,(a0)        ; puddleSize, Flags,Threshold
  1259.         move.l    12(a1),12(a0)        ; next block
  1260.         move.l    a0,12(a1)        ; splice in block
  1261.         lea    24(a0),a1        ; first free location here
  1262.         move.l    a1,16(a0)
  1263.         subi.l    #24,d3            ; for header info
  1264.         move.l    d3,20(a0)        ; amount free in this block
  1265.  
  1266.         move.l    d6,d0            ; restore size
  1267.  
  1268. .gotspace    sub.l    d0,20(a0)        ; sub from amount free
  1269.         bmi.b    .err            ; threshold >= puddlesize!
  1270.  
  1271.         move.l    16(a0),a1        ; free space
  1272.         add.l    d0,16(a0)        ; next free space
  1273.  
  1274.         movea.l    a1,a0
  1275.         bra.b    .out
  1276.  
  1277. .err        add.l    d0,20(a0)        ; restore free space
  1278.         moveq    #0,d0
  1279.         suba.l    a0,a0            ; no memory
  1280.  
  1281. .out        move.l    a0,d0
  1282.         movem.l    (sp)+,d2-d7/a2-a6
  1283.         rts
  1284.  
  1285. ;------------------------------------------------------------------------
  1286. ;------------------------------------------------------------------------
  1287. ;------------------------------------------------------------------------
  1288. ;------------------------------------------------------------------------
  1289.  
  1290. MUSMemPtr    dc.l    0
  1291. MUSMemSize    dc.l    0
  1292.  
  1293. ;------------------------------------------------------------------------
  1294.  
  1295. midifileproblem    dc.b    "Error opening MIDI_Instruments file!",0
  1296.  
  1297. dosproblem    dc.b    "Error reading MIDI_Instruments file!",0
  1298.  
  1299. memproblem    dc.b    "Not enough memory for music!",0
  1300.  
  1301. notmusfile    dc.b    "Music lump in WAD file is not .MUS format!",0
  1302.  
  1303. damagedfile    dc.b    "Damaged MIDI_Instruments or WAD file!",0
  1304.  
  1305. cantopenaud    dc.b    "Can't open audio.device for music!",0
  1306.  
  1307. cantgetchan    dc.b    "Can't allocate channels for music!",0
  1308.  
  1309.         cnop    0,4
  1310.  
  1311. ;------------------------------------------------------------------------
  1312. ; bit 0 = close, bit 1 = file loaded, bit 2 = playing, bit 3 = paused
  1313. ; bit 4 = loop, bit 5 = attention, bit 6 = gadget down, bit 7 = rev/FF
  1314. Flags        dc.b    0
  1315. Flags2        dc.b    0            ; backup of Flags
  1316.  
  1317. ; bit 0,1 = dotick
  1318. Flags3        dc.b    0
  1319.  
  1320.         cnop    0,4
  1321. per        dc.w    0
  1322. per2        dc.w    0    ; period for 11048 Hz
  1323.  
  1324. ;------------------------------------------------------------------------
  1325.         cnop    0,4
  1326.  
  1327. EventTable    dc.w    Release-EventTable
  1328.         dc.w    PlayNote-EventTable
  1329.         dc.w    Pitch-EventTable
  1330.         dc.w    Tempo-EventTable
  1331.         dc.w    ChangeCtrl-EventTable
  1332.         dc.w    NoEvent-EventTable
  1333.         dc.w    EndScore-EventTable
  1334.         dc.w    NoEvent-EventTable
  1335.  
  1336. ;------------------------------------------------------------------------
  1337.  
  1338.         cnop    0,4
  1339.  
  1340. looping        dc.l    0
  1341. musicdies    dc.l    -1
  1342.  
  1343. MyTicks        dc.l    0
  1344.  
  1345. PrevDelay    dc.l    0
  1346.  
  1347. AudioPort    dc.l    0,0
  1348.         dc.b    NT_MSGPORT,0        ; LN_TYPE, LN_PRI
  1349.         dc.l    0            ; LN_NAME
  1350.         dc.b    PA_SIGNAL        ; mp_Flags
  1351.         dc.b    0            ; mp_SigBit
  1352. AudioTask    dc.l    0            ; mp_SigTask
  1353. .1        dc.l    .2
  1354. .2        dc.l    0
  1355.         dc.l    .1
  1356.  
  1357.         cnop    0,4
  1358.  
  1359. AudioIO        dc.l    0,0
  1360.         dc.b    NT_REPLYMSG,0        ; LN_TYPE, LN_PRI
  1361.         dc.l    0            ; LN_NAME
  1362.         dc.l    AudioPort        ; mn_ReplyPort
  1363.         dc.w    68            ; mn_Length
  1364.         dc.l    0            ; IO_DEVICE
  1365.         dc.l    0            ; IO_UNIT
  1366.         dc.w    0            ; IO_COMMAND
  1367.         dc.b    0            ; IO_FLAGS
  1368.         dc.b    0            ; IO_ERROR
  1369.         dc.w    0            ; ioa_AllocKey
  1370.         dc.l    0            ; ioa_Data
  1371.         dc.l    0            ; ioa_Length
  1372.         dc.w    0            ; ioa_Period
  1373.         dc.w    0            ; ioa_Volume
  1374.         dc.w    0            ; ioa_Cycles
  1375.         dc.l    0,0            ; ioa_WriteMsg
  1376.         dc.b    0,0
  1377.         dc.l    0
  1378.         dc.l    0
  1379.         dc.w    0
  1380.  
  1381.         cnop    0,4
  1382.  
  1383. AInt2        dc.l    0,0
  1384.         dc.b    NT_INTERRUPT,0        ; LN_TYPE, LN_PRI
  1385.         dc.l    TPortName        ; LN_NAME
  1386.         dc.l    0            ; IS_DATA
  1387.         dc.l    AudioINT2        ; IS_CODE
  1388.  
  1389. MusPtr        dc.l    0
  1390. MusIndex    dc.l    0
  1391. MusDelay    dc.l    0
  1392. OldAInt2    dc.l    0
  1393.  
  1394. AudioAlloc    dc.b    $0c            ; Amiga channels to allocate
  1395.  
  1396. AudioName    dc.b    'audio.device',0
  1397. TPortName    dc.b    'ADoom-MUS',0
  1398. AudioOK        dc.b    0
  1399. AudioCh        dc.b    0
  1400. musicarg    dc.b    "-music",0
  1401.  
  1402. ;--------------------------------------
  1403.  
  1404.         CNOP    0,4
  1405.  
  1406. ; bit set if voice is in use (0-15=music voices,16-31=sfx voices)
  1407.  
  1408. VoiceAvail    dc.l    0
  1409.  
  1410.  
  1411. ; bit 0 = stop processing, bit 1 = buffer indicator
  1412.  
  1413. MusFlag        dc.b    0
  1414.  
  1415. ;--------------------------------------------------------------------
  1416.  
  1417.         CNOP    0,4
  1418.  
  1419. NoteTable    dc.l    65536/64,69433/64,73562/64,77936/64,82570/64,87480/64,92682/64,98193/64,104032/64,110218/64,116772/64,123715/64
  1420.         dc.l    65536/32,69433/32,73562/32,77936/32,82570/32,87480/32,92682/32,98193/32,104032/32,110218/32,116772/32,123715/32
  1421.         dc.l    65536/16,69433/16,73562/16,77936/16,82570/16,87480/16,92682/16,98193/16,104032/16,110218/16,116772/16,123715/16
  1422.         dc.l    65536/8,69433/8,73562/8,77936/8,82570/8,87480/8,92682/8,98193/8,104032/8,110218/8,116772/8,123715/8
  1423.         dc.l    65536/4,69433/4,73562/4,77936/4,82570/4,87480/4,92682/4,98193/4,104032/4,110218/4,116772/4,123715/4
  1424.         dc.l    65536/2,69433/2,73562/2,77936/2,82570/2,87480/2,92682/2,98193/2,104032/2,110218/2,116772/2,123715/2
  1425.         dc.l    65536,69433,73562,77936,82570,87480,92682,98193,104032,110218,116772,123715
  1426.         dc.l    65536*2,69433*2,73562*2,77936*2,82570*2,87480*2,92682*2,98193*2,104032*2,110218*2,116772*2,123715*2
  1427.         dc.l    65536*4,69433*4,73562*4,77936*4,82570*4,87480*4,92682*4,98193*4,104032*4,110218*4,116772*4,123715*4
  1428.         dc.l    65536*8,69433*8,73562*8,77936*8,82570*8,87480*8,92682*8,98193*8,104032*8,110218*8,116772*8,123715*8
  1429.         dc.l    65536*16,69433*16,73562*16,77936*16,82570*16,87480*16,92682*16,98193*16
  1430.  
  1431. ;------------------------------------------------------------------------
  1432.  
  1433. PitchTable:
  1434.  
  1435. pitch_ix    SET    128
  1436.  
  1437.         REPT    128
  1438.         dc.l    -3678*pitch_ix/64
  1439. pitch_ix    SET    pitch_ix-1
  1440.         ENDR
  1441.  
  1442.         REPT    128
  1443.         dc.l    3897*pitch_ix/64
  1444. pitch_ix    SET    pitch_ix+1
  1445.         ENDR
  1446.  
  1447. ;------------------------------------------------------------------------
  1448.  
  1449.         CNOP    0,4
  1450.  
  1451. AudioCh2Buf    dc.l    chipbuffer2
  1452. AudioCh2Ptr    dc.l    chipbuffer2
  1453. AudioCh2Vol    dc.w    64
  1454.  
  1455.         CNOP    0,4
  1456.  
  1457. AudioCh3Buf    dc.l    chipbuffer3
  1458. AudioCh3Ptr    dc.l    chipbuffer3
  1459. AudioCh3Vol    dc.w    64
  1460.  
  1461. ;------------------------------------------------------------------------
  1462.  
  1463.         STRUCTURE MusChannel,0
  1464.         APTR    ch_Instr
  1465.         APTR    ch_Map
  1466.         ULONG    ch_Pitch
  1467.         BYTE    ch_Vol
  1468.         BYTE    ch_Pan
  1469.  
  1470.  
  1471.         CNOP    0,4
  1472.  
  1473. Channels    dc.l    Channel0,Channel1,Channel2,Channel3
  1474.         dc.l    Channel4,Channel5,Channel6,Channel7
  1475.         dc.l    Channel8,Channel9,Channel10,Channel11
  1476.         dc.l    Channel12,Channel13,Channel14,Channel15
  1477.  
  1478.  
  1479.         CNOP    0,4
  1480.  
  1481. Channel0    dc.l    0        ; instrument
  1482.         dc.l    Channel0Map    ; note to voice map
  1483.         dc.l    0        ; pitch wheel setting
  1484.         dc.b    0        ; volume
  1485.         dc.b    0        ; pan setting
  1486.  
  1487.         CNOP    0,4
  1488.  
  1489. Channel1    dc.l    0        ; instrument
  1490.         dc.l    Channel1Map    ; note to voice map
  1491.         dc.l    0        ; pitch wheel setting
  1492.         dc.b    0        ; volume
  1493.         dc.b    0        ; pan setting
  1494.  
  1495.         CNOP    0,4
  1496.  
  1497. Channel2    dc.l    0        ; instrument
  1498.         dc.l    Channel2Map    ; note to voice map
  1499.         dc.l    0        ; pitch wheel setting
  1500.         dc.b    0        ; volume
  1501.         dc.b    0        ; pan setting
  1502.  
  1503.         CNOP    0,4
  1504.  
  1505. Channel3    dc.l    0        ; instrument
  1506.         dc.l    Channel3Map    ; note to voice map
  1507.         dc.l    0        ; pitch wheel setting
  1508.         dc.b    0        ; volume
  1509.         dc.b    0        ; pan setting
  1510.  
  1511.         CNOP    0,4
  1512.  
  1513. Channel4    dc.l    0        ; instrument
  1514.         dc.l    Channel4Map    ; note to voice map
  1515.         dc.l    0        ; pitch wheel setting
  1516.         dc.b    0        ; volume
  1517.         dc.b    0        ; pan setting
  1518.  
  1519.         CNOP    0,4
  1520.  
  1521. Channel5    dc.l    0        ; instrument
  1522.         dc.l    Channel5Map    ; note to voice map
  1523.         dc.l    0        ; pitch wheel setting
  1524.         dc.b    0        ; volume
  1525.         dc.b    0        ; pan setting
  1526.  
  1527.         CNOP    0,4
  1528.  
  1529. Channel6    dc.l    0        ; instrument
  1530.         dc.l    Channel6Map    ; note to voice map
  1531.         dc.l    0        ; pitch wheel setting
  1532.         dc.b    0        ; volume
  1533.         dc.b    0        ; pan setting
  1534.  
  1535.         CNOP    0,4
  1536.  
  1537. Channel7    dc.l    0        ; instrument
  1538.         dc.l    Channel7Map    ; note to voice map
  1539.         dc.l    0        ; pitch wheel setting
  1540.         dc.b    0        ; volume
  1541.         dc.b    0        ; pan setting
  1542.  
  1543.         CNOP    0,4
  1544.  
  1545. Channel8    dc.l    0        ; instrument
  1546.         dc.l    Channel8Map    ; note to voice map
  1547.         dc.l    0        ; pitch wheel setting
  1548.         dc.b    0        ; volume
  1549.         dc.b    0        ; pan setting
  1550.  
  1551.         CNOP    0,4
  1552.  
  1553. Channel9    dc.l    0        ; instrument
  1554.         dc.l    Channel9Map    ; note to voice map
  1555.         dc.l    0        ; pitch wheel setting
  1556.         dc.b    0        ; volume
  1557.         dc.b    0        ; pan setting
  1558.  
  1559.         CNOP    0,4
  1560.  
  1561. Channel10    dc.l    0        ; instrument
  1562.         dc.l    Channel10Map    ; note to voice map
  1563.         dc.l    0        ; pitch wheel setting
  1564.         dc.b    0        ; volume
  1565.         dc.b    0        ; pan setting
  1566.  
  1567.         CNOP    0,4
  1568.  
  1569. Channel11    dc.l    0        ; instrument
  1570.         dc.l    Channel11Map    ; note to voice map
  1571.         dc.l    0        ; pitch wheel setting
  1572.         dc.b    0        ; volume
  1573.         dc.b    0        ; pan setting
  1574.  
  1575.         CNOP    0,4
  1576.  
  1577. Channel12    dc.l    0        ; instrument
  1578.         dc.l    Channel12Map    ; note to voice map
  1579.         dc.l    0        ; pitch wheel setting
  1580.         dc.b    0        ; volume
  1581.         dc.b    0        ; pan setting
  1582.  
  1583.         CNOP    0,4
  1584.  
  1585. Channel13    dc.l    0        ; instrument
  1586.         dc.l    Channel13Map    ; note to voice map
  1587.         dc.l    0        ; pitch wheel setting
  1588.         dc.b    0        ; volume
  1589.         dc.b    0        ; pan setting
  1590.  
  1591.         CNOP    0,4
  1592.  
  1593. Channel14    dc.l    0        ; instrument
  1594.         dc.l    Channel14Map    ; note to voice map
  1595.         dc.l    0        ; pitch wheel setting
  1596.         dc.b    0        ; volume
  1597.         dc.b    0        ; pan setting
  1598.  
  1599.         CNOP    0,4
  1600.  
  1601. Channel15    dc.l    0        ; instrument
  1602.         dc.l    Channel15Map    ; note to voice map
  1603.         dc.l    0        ; pitch wheel setting
  1604.         dc.b    0        ; volume
  1605.         dc.b    0        ; pan setting
  1606.  
  1607.  
  1608.         CNOP    0,4
  1609.  
  1610. Channel0Map    dcb.b    128,0
  1611. Channel1Map    dcb.b    128,0
  1612. Channel2Map    dcb.b    128,0
  1613. Channel3Map    dcb.b    128,0
  1614. Channel4Map    dcb.b    128,0
  1615. Channel5Map    dcb.b    128,0
  1616. Channel6Map    dcb.b    128,0
  1617. Channel7Map    dcb.b    128,0
  1618. Channel8Map    dcb.b    128,0
  1619. Channel9Map    dcb.b    128,0
  1620. Channel10Map    dcb.b    128,0
  1621. Channel11Map    dcb.b    128,0
  1622. Channel12Map    dcb.b    128,0
  1623. Channel13Map    dcb.b    128,0
  1624. Channel14Map    dcb.b    128,0
  1625. Channel15Map    dcb.b    128,0
  1626.  
  1627. ;--------------------------------------
  1628.  
  1629.         STRUCTURE AudioVoice,0
  1630.         APTR    vc_Next
  1631.         APTR    vc_Channel
  1632.         APTR    vc_Wave
  1633.         ULONG    vc_Index
  1634.         ULONG    vc_Step
  1635.         ULONG    vc_Loop
  1636.         ULONG    vc_Length
  1637.         BYTE    vc_Vol
  1638.         BYTE    vc_Flags    ; b7 = SFX, b1 = RLS, b0 = EN
  1639.  
  1640.         CNOP    0,4
  1641.  
  1642. Voices        dc.l    Voice0,Voice1,Voice2,Voice3
  1643.         dc.l    Voice4,Voice5,Voice6,Voice7
  1644.         dc.l    Voice8,Voice9,Voice10,Voice11
  1645.         dc.l    Voice12,Voice13,Voice14,Voice15
  1646.  
  1647.         CNOP    0,4
  1648.  
  1649. Voice0        dc.l    Voice1
  1650.         dc.l    0        ; channel back-link
  1651.         dc.l    0        ; instrument wave data
  1652.         dc.l    0        ; sample index
  1653.         dc.l    0        ; sample rate
  1654.         dc.l    0        ; instrument loop point
  1655.         dc.l    0        ; instrument data length
  1656.         dc.b    0        ; voice volume scale
  1657.         dc.b    0        ; voice flags
  1658.  
  1659.         CNOP    0,4
  1660.  
  1661. Voice1        dc.l    Voice2
  1662.         dc.l    0        ; channel back-link
  1663.         dc.l    0        ; instrument wave data
  1664.         dc.l    0        ; sample index
  1665.         dc.l    0        ; sample rate
  1666.         dc.l    0        ; instrument loop point
  1667.         dc.l    0        ; instrument data length
  1668.         dc.b    0        ; voice volume scale
  1669.         dc.b    0        ; voice flags
  1670.  
  1671.         CNOP    0,4
  1672.  
  1673. Voice2        dc.l    Voice3
  1674.         dc.l    0        ; channel back-link
  1675.         dc.l    0        ; instrument wave data
  1676.         dc.l    0        ; sample index
  1677.         dc.l    0        ; sample rate
  1678.         dc.l    0        ; instrument loop point
  1679.         dc.l    0        ; instrument data length
  1680.         dc.b    0        ; voice volume scale
  1681.         dc.b    0        ; voice flags
  1682.  
  1683.         CNOP    0,4
  1684.  
  1685. Voice3        dc.l    Voice4
  1686.         dc.l    0        ; channel back-link
  1687.         dc.l    0        ; instrument wave data
  1688.         dc.l    0        ; sample index
  1689.         dc.l    0        ; sample rate
  1690.         dc.l    0        ; instrument loop point
  1691.         dc.l    0        ; instrument data length
  1692.         dc.b    0        ; voice volume scale
  1693.         dc.b    0        ; voice flags
  1694.  
  1695.         CNOP    0,4
  1696.  
  1697. Voice4        dc.l    Voice5
  1698.         dc.l    0        ; channel back-link
  1699.         dc.l    0        ; instrument wave data
  1700.         dc.l    0        ; sample index
  1701.         dc.l    0        ; sample rate
  1702.         dc.l    0        ; instrument loop point
  1703.         dc.l    0        ; instrument data length
  1704.         dc.b    0        ; voice volume scale
  1705.         dc.b    0        ; voice flags
  1706.  
  1707.         CNOP    0,4
  1708.  
  1709. Voice5        dc.l    Voice6
  1710.         dc.l    0        ; channel back-link
  1711.         dc.l    0        ; instrument wave data
  1712.         dc.l    0        ; sample index
  1713.         dc.l    0        ; sample rate
  1714.         dc.l    0        ; instrument loop point
  1715.         dc.l    0        ; instrument data length
  1716.         dc.b    0        ; voice volume scale
  1717.         dc.b    0        ; voice flags
  1718.  
  1719.         CNOP    0,4
  1720.  
  1721. Voice6        dc.l    Voice7
  1722.         dc.l    0        ; channel back-link
  1723.         dc.l    0        ; instrument wave data
  1724.         dc.l    0        ; sample index
  1725.         dc.l    0        ; sample rate
  1726.         dc.l    0        ; instrument loop point
  1727.         dc.l    0        ; instrument data length
  1728.         dc.b    0        ; voice volume scale
  1729.         dc.b    0        ; voice flags
  1730.  
  1731.         CNOP    0,4
  1732.  
  1733. Voice7        dc.l    Voice8
  1734.         dc.l    0        ; channel back-link
  1735.         dc.l    0        ; instrument wave data
  1736.         dc.l    0        ; sample index
  1737.         dc.l    0        ; sample rate
  1738.         dc.l    0        ; instrument loop point
  1739.         dc.l    0        ; instrument data length
  1740.         dc.b    0        ; voice volume scale
  1741.         dc.b    0        ; voice flags
  1742.  
  1743.         CNOP    0,4
  1744.  
  1745. Voice8        dc.l    Voice9
  1746.         dc.l    0        ; channel back-link
  1747.         dc.l    0        ; instrument wave data
  1748.         dc.l    0        ; sample index
  1749.         dc.l    0        ; sample rate
  1750.         dc.l    0        ; instrument loop point
  1751.         dc.l    0        ; instrument data length
  1752.         dc.b    0        ; voice volume scale
  1753.         dc.b    0        ; voice flags
  1754.  
  1755.         CNOP    0,4
  1756.  
  1757. Voice9        dc.l    Voice10
  1758.         dc.l    0        ; channel back-link
  1759.         dc.l    0        ; instrument wave data
  1760.         dc.l    0        ; sample index
  1761.         dc.l    0        ; sample rate
  1762.         dc.l    0        ; instrument loop point
  1763.         dc.l    0        ; instrument data length
  1764.         dc.b    0        ; voice volume scale
  1765.         dc.b    0        ; voice flags
  1766.  
  1767.         CNOP    0,4
  1768.  
  1769. Voice10        dc.l    Voice11
  1770.         dc.l    0        ; channel back-link
  1771.         dc.l    0        ; instrument wave data
  1772.         dc.l    0        ; sample index
  1773.         dc.l    0        ; sample rate
  1774.         dc.l    0        ; instrument loop point
  1775.         dc.l    0        ; instrument data length
  1776.         dc.b    0        ; voice volume scale
  1777.         dc.b    0        ; voice flags
  1778.  
  1779.         CNOP    0,4
  1780.  
  1781. Voice11        dc.l    Voice12
  1782.         dc.l    0        ; channel back-link
  1783.         dc.l    0        ; instrument wave data
  1784.         dc.l    0        ; sample index
  1785.         dc.l    0        ; sample rate
  1786.         dc.l    0        ; instrument loop point
  1787.         dc.l    0        ; instrument data length
  1788.         dc.b    0        ; voice volume scale
  1789.         dc.b    0        ; voice flags
  1790.  
  1791.         CNOP    0,4
  1792.  
  1793. Voice12        dc.l    Voice13
  1794.         dc.l    0        ; channel back-link
  1795.         dc.l    0        ; instrument wave data
  1796.         dc.l    0        ; sample index
  1797.         dc.l    0        ; sample rate
  1798.         dc.l    0        ; instrument loop point
  1799.         dc.l    0        ; instrument data length
  1800.         dc.b    0        ; voice volume scale
  1801.         dc.b    0        ; voice flags
  1802.  
  1803.         CNOP    0,4
  1804.  
  1805. Voice13        dc.l    Voice14
  1806.         dc.l    0        ; channel back-link
  1807.         dc.l    0        ; instrument wave data
  1808.         dc.l    0        ; sample index
  1809.         dc.l    0        ; sample rate
  1810.         dc.l    0        ; instrument loop point
  1811.         dc.l    0        ; instrument data length
  1812.         dc.b    0        ; voice volume scale
  1813.         dc.b    0        ; voice flags
  1814.  
  1815.         CNOP    0,4
  1816.  
  1817. Voice14        dc.l    Voice15
  1818.         dc.l    0        ; channel back-link
  1819.         dc.l    0        ; instrument wave data
  1820.         dc.l    0        ; sample index
  1821.         dc.l    0        ; sample rate
  1822.         dc.l    0        ; instrument loop point
  1823.         dc.l    0        ; instrument data length
  1824.         dc.b    0        ; voice volume scale
  1825.         dc.b    0        ; voice flags
  1826.  
  1827.         CNOP    0,4
  1828.  
  1829. Voice15        dc.l    0
  1830.         dc.l    0        ; channel back-link
  1831.         dc.l    0        ; instrument wave data
  1832.         dc.l    0        ; sample index
  1833.         dc.l    0        ; sample rate
  1834.         dc.l    0        ; instrument loop point
  1835.         dc.l    0        ; instrument data length
  1836.         dc.b    0        ; voice volume scale
  1837.         dc.b    0        ; voice flags
  1838.  
  1839. ;--------------------------------------
  1840.  
  1841.         STRUCTURE InstrumentRec,0
  1842.         APTR    in_Wave
  1843.         ULONG    in_Loop
  1844.         ULONG    in_Length
  1845.         BYTE    in_Flags
  1846.         BYTE    in_Base
  1847.  
  1848.  
  1849.         CNOP    0,4
  1850.  
  1851. Instruments    dcb.l    256,0
  1852.  
  1853.         CNOP    0,4
  1854.  
  1855. QuietInst    dc.l    0
  1856.         dc.l    0
  1857.         dc.l    0
  1858.         dc.b    0
  1859.         dc.b    0
  1860.  
  1861.  
  1862.         CNOP    0,4
  1863.  
  1864. InstrHandle    dc.l    0
  1865. InstrFile    dc.l    InstrName
  1866. InstrPool    dc.l    0
  1867.  
  1868. InstrName    dc.b    'PROGDIR:MIDI_Instruments',0
  1869.  
  1870.         CNOP    0,4
  1871.  
  1872. validInstr    dc.b    %11111111    ; (00-07) Piano
  1873.         dc.b    %11111111    ; (08-0F) Chrom Perc
  1874.         dc.b    %11111111    ; (10-17) Organ
  1875.         dc.b    %11111111    ; (18-1F) Guitar
  1876.         dc.b    %11111111    ; (20-27) Bass
  1877.         dc.b    %11111111    ; (28-2F) Strings
  1878.         dc.b    %11111111    ; (30-37) Ensemble
  1879.         dc.b    %11111111    ; (38-3F) Brass
  1880.         dc.b    %11111111    ; (40-47) Reed
  1881.         dc.b    %11111111    ; (48-4F) Pipe
  1882.         dc.b    %11111111    ; (50-57) Synth Lead
  1883.         dc.b    %11111111    ; (58-5F) Synth Pad
  1884.         dc.b    %11111111    ; (60-67) Synth Effects
  1885.         dc.b    %11111111    ; (68-6F) Ethnic
  1886.         dc.b    %11111111    ; (70-77) Percussive
  1887.         dc.b    %11111111    ; (78-7F) SFX
  1888.         dc.b    %00000001    ; (80-87) invalid,Drum
  1889.         dc.b    %11111111    ; (88-8F) Drums/Clap/Hi-Hat
  1890.         dc.b    %11111111    ; (90-97) Hi-Hats/Toms/Cymb1
  1891.         dc.b    %11111111    ; (98-9F) Cymbals/Bells/Slap
  1892.         dc.b    %11111111    ; (A0-A7) Bongos/Congas/Timb
  1893.         dc.b    %11111111    ; (A8-AF) Agogo/Whistles/Gui
  1894.         dc.b    %11111100    ; (B0-B7) Claves/Block/Trian
  1895.         dc.b    %00000000    ; (B8-BF) invalid
  1896.         dc.b    %00000000    ; (C0-C7)
  1897.         dc.b    %00000000    ; (C8-CF)
  1898.         dc.b    %00000000    ; (D0-D7)
  1899.         dc.b    %00000000    ; (D8-DF)
  1900.         dc.b    %00000000    ; (E0-E7)
  1901.         dc.b    %00000000    ; (E8-EF)
  1902.         dc.b    %00000000    ; (F0-F7)
  1903.         dc.b    %00000000    ; (F8-FF)
  1904.  
  1905. ;--------------------------------------------------------------------
  1906.         section    PlayMusChip,data_c
  1907.  
  1908. ClearBuf    dcb.b    160,0
  1909.  
  1910.  
  1911. chipbuffer2    dcb.b    320,0
  1912. chipbuffer3    dcb.b    320,0
  1913.  
  1914. ;------------------------------------------------------------------------
  1915.         section    PlayMusBSS,bss
  1916.  
  1917. EventBlocks    ds.w    32768
  1918.  
  1919.  
  1920. tempAudio    ds.b    160
  1921.  
  1922. ;------------------------------------------------------------------------
  1923.  
  1924.         end
  1925.